<style rel="stylesheet/scss" lang="scss" scoped>
  @import "../../../styles/prod.scss";

  .upload-df {
    vertical-align: top;
    margin-right: 10px;
  }

  .upload-img {
    padding: 0;
  }

  .responser-item {
    margin-bottom: 10px;
  }
</style>
<template>
  <!-- 产品档案 -->
  <div class="app-container calendar-list-container">
    <div class="pds-tip-green">
      <!-- <p>选择产品小类： -->
      <!-- <el-cascader :options="basicForm[4].options" :props="{value:'id'}" v-model="pdsFileModelBaseDto.pdsConfCategory" @change="categoryChanged"></el-cascader> -->
      <div class="title">选择产品小类：
        <el-cascader :options="basicForm[4].options"
                     :props="{value:'id'}"
                     v-model="pdsFileModelBaseDto.pdsConfCategory"></el-cascader>
        <!-- <div class="pds-tip"> -->
        <!-- <el-cascader :options="basicForm[4].options" :props="{value:'id'}" v-model="pdsFileModelBaseDto.pdsConfCategory" @change="categoryChanged"></el-cascader> -->
        <el-select v-model="pdsFileModelBaseDto.standard">
          <el-option
            v-for="item in [{labelEnUs:'EnStandard',labelZhCh:'欧标',value:1},{labelEnUs:'UsStandard',labelZhCh:'美标',value:2}]"
            :key="'standard' + item.value" :label="language=='en'?item.labelEnUs:item.labelZhCh" :value="item.value">
          </el-option>
        </el-select>
      </div>
    </div>
    <!-- 基本属性 -->
    <custom-card title="基本信息" class="mt-10">
      <template>
        <basic-form :basicInfo="basicForm" :ruleForm="pdsFileModelBaseDto" ref="basicForm" :lang="language"
                    :useRule="false"></basic-form>
      </template>
    </custom-card>
    <!-- 责任人 -->
    <custom-card title="责任人" class="mt-30">
      <template>
        <el-form ref="principalsForm" label-width="40%" label-suffix="：" :model="detail.pdsPlanningPrincipals"
                 v-if="detail.pdsPlanningPrincipals">
          <el-form-item :label="item.label" :prop="item.key" v-for="(item, index) in principalLabelList"
                        :key="'pri' + index" :rules="{required: true}">
            <el-select v-model="detail.pdsPlanningPrincipals[item.key]" placeholder="请选择" style="width:100%">
              <el-option v-for="(subItem, index) in item.options" :key="'principal' + index" :label="subItem.name"
                         :value="subItem.id">
              </el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <div class="pds-info-tip" style="margin-top:30px">
          注：项目经理需根据此项目开发需求，确定相关外形设计、认证、测试、采购和品保等人员，并在附录1中填写。
        </div>
        <div class="pds-info-tip">
          注：项目经理根据此项目开发情况，完成附录3 中的具体个节点时间计划安排。
        </div>
      </template>
    </custom-card>
    <!-- 销售区域 -->
    <custom-card title="销售区域/国家" class="mt-30">
      <template>
        <el-form label-width="140px" class="mt-20">
          <el-form-item label="请选择：">
            <el-checkbox-group v-model="detail.pdsPlanningModelSalesAreasList">
              <el-checkbox border v-for="option in countryList" :key="option.id" :label="option.value">
                {{language=='en'?option.labelEnUs:option.labelZhCh}}
              </el-checkbox>
            </el-checkbox-group>
          </el-form-item>
          <el-form-item label="备注：">
            <el-input type="textarea" placeholder="请输入内容" style="width:60%"
                      v-model="pdsFileModelBaseDto.salesAreaRemark"></el-input>
          </el-form-item>
        </el-form>
        <div class="pds-info-tip">
          注：项目经理、认证工程师需根据所选区域、国家来确定所需认证。并在附录2中填写完成。
        </div>
      </template>
    </custom-card>
    <!-- 说明书语言 -->
    <custom-card title="说明书语言要求" class="mt-30">
      <template>
        <el-form label-width="140px" class="mt-30" v-if="detail.pdsPlanningManual">
          <el-form-item label="说明书语言要求：" required>
            <el-checkbox-group v-model="detail.pdsPlanningManual.manualLanguageDvs">
              <el-checkbox border v-for="option in languageList" :key="option.id" :label="option.value">
                {{language=='en'?option.labelEnUs:option.labelZhCh}}
              </el-checkbox>
            </el-checkbox-group>
          </el-form-item>
          <el-form-item label="说明书格式：">
            <el-input v-model="detail.pdsPlanningManual.manualFormat" type="textarea" placeholder="请输入内容"
                      style="width:60%"></el-input>
          </el-form-item>
        </el-form>
      </template>
    </custom-card>
    <!-- 市场定位 -->
    <custom-card title="市场定位" class="mt-30">
      <template>
        <el-table :data="detail.pdsConfMarketList" border fit highlight-current-row style="width: 100%">
          <el-table-column min-width="20%" align="center" label="级别" prop="marketLevelDv">
          </el-table-column>
          <el-table-column min-width="30%" align="center" label="客户群" prop="customerGroupDv">
          </el-table-column>
          <el-table-column min-width="10%" align="center" label="选择">
            <template slot-scope="scope">
              <el-checkbox v-model="scope.row.isChecked"></el-checkbox>
            </template>
          </el-table-column>
          <el-table-column min-width="40%" align="center" label="备注">
            <template slot-scope="scope">
              <el-input class="filter-item" v-model="detail.pdsConfMarketList[scope.$index].remark" placeholder="请输入内容"
                        required></el-input>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </custom-card>
    <!-- 包装方式 -->
    <custom-card title="包装方式" class="mt-30">
      <el-form>
        <el-form ref="packingForm" label-width="140px" label-suffix="：" :model="detail.pdsPlanningPacking"
                 v-if="detail.pdsPlanningPacking">
          <el-form-item label="是否有外箱" required>
            <el-radio-group v-model="detail.pdsPlanningPacking.outerBox" style="width:120px">
              <el-radio v-for="option in packageData.outerBoxOptions" :key="option.value" :label="option.value">
                {{language=='en'?option.labelEnUs:option.labelZhCh}}
              </el-radio>
            </el-radio-group>
            <el-input v-model="detail.pdsPlanningPacking.outerBoxCapacity" type="number" style="width:200px"
                      placeholder="请输入几台一包" v-show="detail.pdsPlanningPacking.outerBox==1"></el-input>
          </el-form-item>
          <el-form-item label="包装类型" required>
            <el-radio-group v-model="detail.pdsPlanningPacking.packageType">
              <el-radio v-for="option in packageData.packageTypesOptions" :key="option.value" :label="option.value">
                {{language=='en'?option.labelEnUs:option.labelZhCh}}
              </el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="包装标准" required>
            <el-radio-group v-model="detail.pdsPlanningPacking.packageStandard">
              <el-radio v-for="option in packageData.packageStandardOptions" :key="option.value" :label="option.value">
                {{language=='en'?option.labelEnUs:option.labelZhCh}}
              </el-radio>
            </el-radio-group>
          </el-form-item>
        </el-form>
      </el-form>
    </custom-card>
    <!-- 产品档案 -->
    <prod-file ref="prodfile" :standard="pdsFileModelBaseDto.standard"></prod-file>
    <!-- 竞品对象 -->
    <custom-card title="竞品对象" class="mt-30">
      <template>
        <upload-list uploadFileId="benchmark" type="benchmark" v-model="detail.pdsBenchmarkList"></upload-list>
      </template>
    </custom-card>

    <!-- 使用者期望和产品关键描述 -->
    <custom-card title="使用者期望和产品关键描述" class="mt-30">
      <template>
        <el-table :data="detail.pdsPlanningExpectationList" border fit highlight-current-row style="width: 100%">
          <el-table-column min-width="20%" align="center" label="" prop="dataLabel">
          </el-table-column>
          <el-table-column min-width="40%" align="center" label="描述">
            <template slot-scope="scope">
              <el-input class="filter-item" v-model="detail.pdsPlanningExpectationList[scope.$index].expectationValue"
                        placeholder="请输入内容" required></el-input>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </custom-card>
    <!-- 目标成本 -->
    <custom-card title="目标成本" class="mt-30">
      <template>
        <el-table :data="detail.pdsPlanningCostList" border fit highlight-current-row style="width: 100%">
          <el-table-column min-width="40%" align="center" label="" prop="dataLabel">
          </el-table-column>
          <el-table-column align="center" label="成本&预算">
            <template slot-scope="scope">
              <el-input type="number" min="0" class="filter-item"
                        v-model="detail.pdsPlanningCostList[scope.$index].costValue" placeholder="请输入内容"
                        required></el-input>
            </template>
          </el-table-column>
          <el-table-column align="center" label="承担方">
            <template slot-scope="scope">
              <el-input class="filter-item" v-model="detail.pdsPlanningCostList[scope.$index].bearer"
                        placeholder="请输入内容" required></el-input>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </custom-card>

    <!-- 知识产权归属 -->
    <custom-card title="知识产权归属" class="mt-30">
      <template>
        <el-button size="small" type="success" @click="ipVisible = true">添加</el-button>
        <el-table :data="detail.pdsPlanningIpList" border fit highlight-current-row style="width: 100%">
          <el-table-column align="center" label="" prop="dataLabel">
          </el-table-column>
          <el-table-column align="center" label="归属">
            <template slot-scope="scope">
              <el-input class="filter-item" v-model="detail.pdsPlanningIpList[scope.$index].ipAscription"
                        placeholder="请输入内容" required></el-input>
            </template>
          </el-table-column>
          <el-table-column align="center" label="保护国家">
            <template slot-scope="scope">
              <el-input class="filter-item" v-model="detail.pdsPlanningIpList[scope.$index].ipProtection"
                        placeholder="请输入内容" required></el-input>
            </template>
          </el-table-column>
          <el-table-column width="80px" align="center" label="操作">
            <template slot-scope="scope">
              <el-button size="small" type="danger" @click="delIp(scope.$index)">删除</el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </custom-card>

    <!-- 文档附件 -->
    <custom-card title="文档附件" class="mt-30">
      <template>
        <upload-list uploadFileId="eipFile" type="eipFile" v-model="detail.eipFileList"></upload-list>
      </template>
    </custom-card>
    <div class="pds-btm" style="margin-top:20px">
      <div v-if="pdsFileModelBaseDto.id && pdsFileModelBaseDto.status == 0">
        已保存草稿
        <span class="tip">{{pdsFileModelBaseDto.updateTime | formatTime}}</span>
      </div>
      <div class="right">
        <el-button class="filter-item" type="default" @click="cancel()">取消</el-button>
        <el-button class="filter-item" type="warning" @click="submitForm(0)" :loading="loading">保存草稿</el-button>
        <el-button class="filter-item" type="primary" @click="submitForm(1)" :loading="loading">提交</el-button>
      </div>
    </div>

    <el-dialog title="添加知识产权" :visible.sync="ipVisible" width="30%">
      <p>请选择知识产权</p>
      <el-select v-model="ipIndex" placeholder="请选择">
        <el-option v-for="(item, index) in ipList" :key="'ip' + index" :label="item.dataLabel" :value="index"
                   :disabled="item.disabled">
        </el-option>
      </el-select>

      <span slot="footer" class="dialog-footer">
        <el-button @click="ipVisible = false">取 消</el-button>
        <el-button type="primary" @click="chooseIp">确 定</el-button>
      </span>
    </el-dialog>

  </div>
</template>

<script>
  import {mapGetters} from 'vuex';
  import BasicForm from '@/components/BasicForm/index';
  import UploadList from '@/components/UploadList/index';
  import * as baseApi from '@/api/common/index';
  import * as prodApi from '@/api/product/index';
  import * as planApi from '@/api/product/plan/index';
  import ProdFile from '@/components/Product/prodFile';

  export default {
    name: 'user',
    components: {
      BasicForm,
      UploadList,
      ProdFile
      // 'depart-selector': () =>
      //   import ('./components/departSelector')
    },
    data() {
      return {
        pageLoading: true,
        loading: false,
        /* 基本信息 */
        pdsFileModelBaseDtoInit: {
          projectStatus: null,
          projectLevelDv: '',
          salesUserName: '',
          productName: '',
          pdsConfCategory: [],
          certsDvs: [],
          customerIds: [],
          pdsPlanningModelPicsList: [],
          pdsFileModelPbsPicsList: [],
          salesAreaRemark: '',
          standard: 1
        },
        pdsFileModelBaseDto: {},
        detailInit: {
          /* 负责人 */
          pdsPlanningPrincipals: {
            marketingCenterPrincipal: null,
            pmtPrincipal: null,
            rdPm: null,
            rdSupervisor: null
          },
          /* 销售区域/国家 */
          pdsPlanningModelSalesAreasList: [],
          /* 说明书 */
          pdsPlanningManual: {
            manualFormat: '',
            manualLanguageDvs: []
          },
          /* 市场定位 */
          pdsConfMarketList: [],
          /* 包装方式 */
          pdsPlanningPacking: {
            outerBox: 0,
            outerBoxCapacity: null,
            packageStandard: 1,
            packageType: 'exportBox'
          },
          /* 使用者期望 */
          pdsPlanningExpectationList: [],
          /* 目标成本 */
          pdsPlanningCostList: [],
          /* 知识产权 */
          pdsPlanningIpList: [],
          /* 竞品文件 */
          pdsBenchmarkList: [],
          /* 文档附件 */
          eipFileList: []
        },
        detail: {},
        principalLabelList: [
          {label: '营销中心（Sales & Marketing Center）', key: 'marketingCenterPrincipal', id: 16, options: []},
          {label: '产品管理部（PMT contact）', key: 'pmtPrincipal', id: 22, options: []},
          {label: '研发中心-项目经理（R&D Project Manager）', key: 'rdPm', id: 15, options: []},
          {label: '研发中心-二级主管 (R&D Supervisor)', key: 'rdSupervisor', id: 21, options: []}
        ],
        countryList: [],
        languageList: [],
        marketFormList: [],
        packageData: {
          outerBoxOptions: [
            {
              labelZhCh: '是',
              labelEnUs: 'Y',
              value: 1,
              id: 1
            },
            {
              labelZhCh: '否',
              labelEnUs: 'N',
              value: 0,
              id: 0
            }
          ],
          packageTypesOptions: [
            {
              value: 'exportBox',
              labelZhCh: '单白盒',
              labelEnUs: '单白盒'
            },
            {
              value: 'colorBox',
              labelZhCh: '彩盒',
              labelEnUs: '彩盒'
            },
            {
              value: 'bmcBox',
              labelZhCh: '吹塑盒',
              labelEnUs: '吹塑盒'
            },
            {
              value: 'nylonBag',
              labelZhCh: '尼龙袋',
              labelEnUs: '尼龙袋'
            }
          ],
          packageStandardOptions: [
            {
              value: 1,
              labelZhCh: 'ISTA 1A',
              labelEnUs: 'ISTA 1A'
            },
            {
              value: 2,
              labelZhCh: 'ISTA 2A',
              labelEnUs: 'ISTA 2A'
            },
            {
              value: 3,
              labelZhCh: 'ISTA 3A',
              labelEnUs: 'ISTA 3A'
            }
          ]
        },
        packageTypeList: ['exportBox', 'colorBox', 'bmcBox', 'nylonBag'],
        ipList: [],
        ipVisible: false,
        ipIndex: null,
        basicForm: [
          {
            label: 'product.plan.projectStatus',
            unit: '',
            element: 'select',
            type: '',
            name: 'projectStatus',
            options: [
              {
                value: 0,
                labelEnUs: '意向',
                labelZhCh: '意向'
              },
              {
                value: 1,
                labelEnUs: '立项',
                labelZhCh: '立项'
              }
            ],
            isRequired: true
          },
          {
            label: 'product.plan.projectLevel',
            unit: '',
            element: 'select',
            type: '',
            name: 'projectLevelDv',
            dictCode: 'pro_plan_level',
            isRequired: true
          },
          {
            label: 'product.plan.salesUser',
            unit: '',
            element: 'departAdmin',
            type: '',
            name: 'salesUser',
            options: [],
            multiple: false,
            isRequired: false
          },
          {
            label: 'product.plan.productName',
            unit: '',
            element: 'input',
            type: '',
            name: 'productName',
            isRequired: true
          },
          {
            label: '产品小类',
            unit: '',
            element: 'cascader',
            type: '',
            name: 'pdsConfCategory',
            options: [],
            props: {
              value: 'id',
              label: this.language == 'en' ? 'nameEn' : 'nameCn'
            },
            hidden: true,
            isRequired: true,
            rule: {required: true, type: 'Array'}
          },
          {
            label: 'product.plan.productModel',
            unit: '',
            element: 'input',
            name: 'productModel',
            type: '',
            isRequired: false
          },
          {
            label: 'product.plan.estimatedSales',
            unit: '',
            element: 'input',
            name: 'estimatedSales',
            type: 'number',
            rules: [
              {required: true},
              {pattern: /^[1-9]\d{0,10}$/, message: '请输入长度不超过11的正整数'}
            ],
            isRequired: true
          },
          {
            label: 'product.plan.productBizModel',
            unit: '',
            element: 'select',
            type: '',
            dictCode: 'prod_file_biz_model',
            name: 'productBizModelDv',
            isRequired: true
          },
          // {
          //   label: '机型码',
          //   unit: '',
          //   element: 'input',
          //   type: '',
          //   isRequired: false
          // },
          {
            label: 'product.plan.salesPeriod',
            unit: '',
            element: 'input',
            append: '年',
            name: 'salesPeriod',
            type: 'number',
            rules: [
              {required: true},
              {pattern: /^[1-9]\d{0,10}$/, message: '请输入长度不超过11的正整数'}
            ],
            isRequired: true
          },
          // {
          //   label: '客户代码',
          //   unit: '',
          //   element: 'select',
          //   name: 'customerCodes', // 支持多选，逗号分隔
          //   type: 'multiple',
          //   options: [],
          //   value: 'code',
          //   labelName: 'name',
          //   search: true,
          //   isRequired: false
          // },
          {
            label: 'product.plan.customerId',
            unit: '',
            element: 'selectFilter',
            options: [],
            name: 'customerIds',
            isMultiple: true,
            type: 'filter',
            // rules: { required: true, type: 'array' },
            isRequired: false
          },
          {
            label: 'product.plan.marketPosition',
            unit: '',
            name: 'marketPositionDv',
            element: 'select',
            dictCode: 'prod_file_market_pos',
            type: '',
            isRequired: true
          },
          {
            label: 'product.plan.afterSalesPeriod',
            element: 'input',
            append: '年',
            type: 'number',
            rules: [
              // { required: true },
              {pattern: /^[1-9]\d{0,10}$/, message: '请输入长度不超过11的正整数'}
            ],
            name: 'afterSalesPeriod',
            // isRequired: true
          },
          {
            label: 'product.plan.life',
            unit: '',
            element: 'input',
            append: '小时',
            type: 'number',
            name: 'life',
            rules: [
              // { required: true },
              {pattern: /^[1-9]\d{0,10}$/, message: '请输入长度不超过11的正整数'}
            ],
            isRequired: false
          },
          {
            label: 'product.plan.certsDvs',
            unit: '',
            element: 'select',
            name: 'certsDvs',
            type: 'multiple',
            isRequired: true
          },
          {
            label: 'product.plan.projectStandardPeriod',
            unit: '',
            element: 'input',
            append: '月',
            type: 'number',
            rules: [
              {required: true},
              {pattern: /^[1-9]\d{0,10}$/, message: '请输入长度不超过11的正整数'}
            ],
            name: 'projectStandardPeriod',
            isRequired: true
          },
          {
            label: 'product.plan.projectPlanningPeriod',
            unit: '',
            element: 'input',
            append: '月',
            type: 'number',
            rules: [
              {required: true},
              {pattern: /^[1-9]\d{0,10}$/, message: '请输入长度不超过11的正整数'}
            ],
            name: 'projectPlanningPeriod',
            isRequired: true
          },
          {
            label: 'product.plan.projectEndDate',
            unit: '',
            element: 'datePicker',
            type: 'date',
            name: 'projectEndDate',
            isRequired: true
          },
          {
            label: 'product.plan.productBrand',
            unit: '',
            element: 'input',
            type: '',
            name: 'productBrandDv',
            isRequired: false
          },
          {
            label: 'product.plan.salesYear',
            unit: '',
            element: 'datePicker',
            type: 'year',
            name: 'salesYear',
            isRequired: true
          },
          {
            label: 'product.plan.productStructureDesign',
            unit: '',
            element: 'textarea',
            type: '',
            name: 'productStructureDesign',
            isRequired: true
          },
          {
            label: 'product.plan.productModelingDesign',
            unit: '',
            element: 'textarea',
            type: '',
            name: 'productModelingDesign',
            isRequired: true
          },
          {
            label: 'product.plan.remark',
            unit: '',
            element: 'textarea',
            type: '',
            name: 'remark',
            isRequired: false
          },
          {
            label: 'product.plan.fileModelPbsPics',
            unit: '',
            element: 'upload',
            type: '',
            name: 'pdsFileModelPbsPicsList',
            isRequired: true
          }
        ]
      };
    },
    computed: {
      ...mapGetters(['elements', 'language'])
    },
    watch: {
      'pdsFileModelBaseDto.pdsConfCategory'(val) {
        if (val.length === 3) {
          this.$refs.prodfile.prodCategoryChanged(val[2]);
        }
      }
    },
    created() {
      this.getDefaultOptions();
      if (!this.$route.query.planId) {
        this.getDefaultSetting();
      }
    },
    methods: {
      /* 页面刷新初始化 */
      refresh() {
        if (this.$route.query.planId) { /* 编辑 */
          this.getDetail();
          this.clearValidate();
        } else { /* 添加 */
          this.pdsFileModelBaseDto = JSON.parse(JSON.stringify(this.pdsFileModelBaseDtoInit));
          this.detail = JSON.parse(JSON.stringify(this.detailInit));
          setTimeout(() => {
            this.$refs.prodfile.dataInit();
          })
          this.clearValidate();
        }
      },
      /* 清除表单验证状态 */
      clearValidate() {
        setTimeout(() => {
          if (this.$refs.basicForm) {
            this.$refs.basicForm.$refs.ruleForm.clearValidate();
          }
          if (this.$refs.principalsForm) {
            this.$refs.principalsForm.clearValidate();
          }
        })
      },
      getDefaultOptions() {
        this.getPdsConfCategoryTree();
        this.getTypeValue('prod_file_biz_model', 7);
        this.getTypeValue('prod_file_market_pos', 10);
        this.getTypeValue('pro_plan_level', 1);
        this.getCertSelect();
        this.getSalesCountry();
        this.getLanguageList();
        this.getPrincipalValue();
        this.getIpList();
        this.clearValidate();
      },
      getDefaultSetting() {
        this.getMarket();
        this.getExpectation();
        this.getCost();
        // this.getCustomerList();
      },
      // categoryChanged(val) {
      //   if (val.length === 3) {
      //     this.$refs.prodfile.prodCategoryChanged(val[2]);
      //   }
      // },
      getDetail() {
        planApi.getDetail({id: this.$route.query.planId}).then(res => {
          this.getSubDetail();
          if (res.code == 200) {
            res.data.pdsConfCategory = res.data.pdsConfCategory || [];
            res.data.certsDvs = res.data.certsDvs || [];
            // res.data.customerIds = res.data.customerIds || [];
            res.data.pdsFileModelPbsPicsList = res.data.pdsPlanningModelPicsList || [];
            this.$set(this, 'pdsFileModelBaseDto', res.data);
            this.getSalesUserList();
            const setMulSelect = str => {
              let arr = str.split(',');
              arr = arr.map(row => Number(row));
              return arr;
            };
            console.log('customerIds',res.data.customerIds)
            this.$set(this.pdsFileModelBaseDto, 'customerIds', setMulSelect(res.data.customerIds));
            /* 客户代码回显 */
            let customerNameArr = [];
            if (res.data.customerNames) customerNameArr = res.data.customerNames.split(',')|| [];
            customerNameArr.map((item, index) => {
              this.$refs.basicForm.getPdsCustomerByName(item);
            })
            console.log('333333');
            console.log('res.data.productCategoryIds', res.data.productCategoryIds);
            console.log('setMulSelect(res.data.productCategoryIds)', setMulSelect(res.data.productCategoryIds));

            this.$set(this.pdsFileModelBaseDto, 'pdsConfCategory', setMulSelect(res.data.productCategoryIds));
            this.$set(this.pdsFileModelBaseDto, 'certsDvs', setMulSelect(res.data.certsDvs));
            // this.$set(
            //   this.pdsFileModelBaseDto,
            //   'pdsFileModelPbsPicsList',
            //   res.data.pdsPlanningModelPicsList
            // );
            console.log('detail', this.pdsFileModelBaseDto);
          }
        });
      },
      getSubDetail() {
        planApi.getSubDetail({id: this.$route.query.planId}).then(res => {
          if (res.code == 200) {
            /* 销售国家 */
            res.data.pdsPlanningModelSalesAreasList = res.data.pdsPlanningModelSalesAreasList.map(item => item.salesAreaDv);
            /* 说明书语言 */
            res.data.pdsPlanningManual.manualLanguageDvs = res.data.pdsPlanningManual.manualLanguageDvs.split(',');
            /* 市场定位 */
            res.data.pdsConfMarketList.map(item => {
              item.isChecked = !!item.isChecked
            })
            /* 包装方式 */
            this.packageTypeList.map(item => {
              if (res.data.pdsPlanningPacking[item]) {
                res.data.pdsPlanningPacking.packageType = item;
              }
            })
            /* 知识产权 */
            this.ipList = JSON.parse(JSON.stringify(res.data.pdsPlanningIpList));
            res.data.pdsPlanningIpList = [];
            this.ipList.map((item, index) => {
              if (item.ipAscription || item.ipProtection) {
                res.data.pdsPlanningIpList.push({
                  ...item,
                  listIndex: index
                })
                item.disabled = true;
              }
            })
            // this.detail = Object.assign(this.detail, res.data);
            this.detail = res.data;

            /* 产品档案 */
            const proDetail = JSON.parse(JSON.stringify(this.detail));
            proDetail.showAccessoriesList = this.detail.pdsPlanningModelAccessories;
            proDetail.showFeaturesList = this.detail.pdsPlanningModelFeaturesList;
            proDetail.showModules = this.detail.pdsModuleItemsAndValueVOList;
            proDetail.pdsConfCategoryArray = this.pdsFileModelBaseDto.pdsConfCategory;
            this.$refs.prodfile.refresh(proDetail);
            console.log('this.detail', this.detail);
            this.clearValidate();
          }
        });
      },
      getPdsConfCategoryTree() {
        prodApi.getPdsConfCategoryTree().then(res => {
          this.basicForm[4].options = res.data;
        });
      },
      /* 获取销售对接人列表 */
      getSalesUserList() {
        if (!this.pdsFileModelBaseDto.salesUser) return;
        baseApi.getUserByIds(this.pdsFileModelBaseDto.salesUser).then(res => {
          if (res.code == 200) {
            this.basicForm[2].options = res.data;
          }
        })
      },
      getTypeValue(code, index) {
        baseApi.getTypeValue(code).then(res => {
          this.$set(this.basicForm[index], 'options', res.data.rows);
        });
      },
      getCertSelect() {
        prodApi.certSelect().then(res => {
          this.basicForm[13].options = res.data;
        });
      },
      getSalesCountry() {
        const codes = 'prod_file_sales_area';
        baseApi.getTypesValue(codes).then(res => {
          this.countryList = res.data[codes];
          this.countryList.map(row => {
            row.salesAreaDv = row.value;
            return row;
          });
          this.$set(this, 'countryList', res.data[codes]);
        });
      },
      getLanguageList() {
        const codes = 'pro_plan_manual';
        baseApi.getTypesValue(codes).then(res => {
          this.languageList = res.data[codes];
          this.$set(this, 'languageList', res.data[codes]);
        });
      },
      /* 客户信息列表 */
      // getCustomerList() {
      //   baseApi.getCustomerList().then(res => {
      //     this.basicForm[9].options = res.data;
      //   });
      // },
      /* 负责人选项列表 */
      async getPrincipalValue() {
        for (let i = 0; i < this.principalLabelList.length; i++) {
          const res = await baseApi.getDepartAdmin({departId: this.principalLabelList[i].id});
          this.principalLabelList[i].options = res.data.rows;
        }
        this.clearValidate();
      },
      /* 市场定位选项列表 */
      getMarket() {
        baseApi.getMarket().then(res => {
          this.detail.pdsConfMarketList = res.data;
          this.detail.pdsConfMarketList.map(item => {
            item.configId = item.id;
            item.isChecked = false;
          })
        });
      },
      /* 使用者期望 */
      getExpectation() {
        baseApi.getExpectation().then(res => {
          const list = [];
          for (let i = 0; i < res.data.length; i++) {
            list.push({
              configId: res.data[i].id,
              // expectationConfigId: res.data[i].id,
              dataLabel: res.data[i].dataLabel,
              expectationValue: ''
            });
          }
          this.detail.pdsPlanningExpectationList = list;
        });
      },
      /* 目标成本 */
      getCost() {
        baseApi.getCost().then(res => {
          const list = [];
          for (let i = 0; i < res.data.length; i++) {
            list.push({
              // costConfigId: res.data[i].id,
              configId: res.data[i].id,
              dataLabel: res.data[i].dataLabel,
              bearer: '',
              costValue: ''
            });
          }
          this.detail.pdsPlanningCostList = list;
        });
      },
      /* 知识产权 */
      getIpList() {
        baseApi.getIpList().then(res => {
          this.ipList = res.data;
        });
      },
      /* 添加知识产权 */
      chooseIp() {
        this.detail.pdsPlanningIpList.push({
          ipAscription: '',
          // ipConfigId: this.ipList[this.ipIndex].id,
          configId: this.ipList[this.ipIndex].id || this.ipList[this.ipIndex].configId,
          dataLabel: this.ipList[this.ipIndex].dataLabel,
          ipProtection: '',
          listIndex: this.ipIndex
        });
        this.ipList[this.ipIndex].disabled = true;
        this.ipVisible = false;
        this.ipIndex = null;
      },
      /* 删除知识产权 */
      delIp(index) {
        this.ipList[
          this.detail.pdsPlanningIpList[index].listIndex
          ].disabled = false;
        this.detail.pdsPlanningIpList.splice(index, 1);
      },
      /* 表单校验 */
      formValidate(formName) {
        return new Promise((resolve, reject) => {
          this.$refs[formName].validate(valid => {
            resolve(valid);
          });
        })
      },
      /* 提交 */
      async submitForm(type) {
        this.detail.status = type;
        const basicFormCheck = await this.$refs.basicForm.submitForm();
        if (!basicFormCheck) {
          this.$message.error('请填写完整基本信息');
          return;
        }
        const moduleFormRes = await this.$refs.prodfile.submitForm();

        /* 目标成本数字校验 */
        let costPat = true;
        this.detail.pdsPlanningCostList.map(item => {
          const reg = /^(0|(\d+(\.\d+)?))$/;  // /^([1-9]\d*)|0$/
          if (item.costValue && !reg.test(item.costValue)) {
            costPat = false;
          }
        })
        if (!costPat) {
          this.$message.info('请正确填写目标成本中成本&预算的数字');
          return;
        }

        if (type) { /* 提交 */
          /* 负责人 */
          const principalsValidate = await this.formValidate('principalsForm');
          if (!principalsValidate) {
            this.$message.error('请选择负责人');
            return;
          }
          /* 销售区域 */
          if (!this.detail.pdsPlanningModelSalesAreasList.length) {
            this.$message.error('请选择销售区域/国家');
            return;
          }
          /* 说明书语言要求 */
          if (!this.detail.pdsPlanningManual.manualLanguageDvs.length) {
            this.$message.error('请选择说明书语言要求');
            return;
          }
          /* 市场定位 */
          let marketFlag = false;
          this.detail.pdsConfMarketList.map(item => {
            if (item.isChecked) {
              marketFlag = true;
            }
          })
          if (!marketFlag) {
            this.$message.error('请选择市场定位');
            return;
          }
          /* 包装方式 */
          if (this.detail.pdsPlanningPacking.outerBox == 1 && !this.detail.pdsPlanningPacking.outerBoxCapacity) {
            this.$message.error('请填写包装方式');
            return;
          }
          /* 产品档案 */
          if (!moduleFormRes.isValid) {
            this.$message.error('请填写完整模组信息');
            return;
          }
          if (!moduleFormRes.data.showFeaturesList.length) {
            this.$message.error('请选择产品特征');
            return;
          }
          /* 使用者期望 */
          let expectationFlag = true;
          this.detail.pdsPlanningExpectationList.map(item => {
            if (!item.expectationValue) {
              expectationFlag = false;
            }
          })
          if (!expectationFlag) {
            this.$message.error('请将使用者期望和产品关键描述填写完整');
            return;
          }
          /* 目标成本 */
          let costFlag = true;
          this.detail.pdsPlanningCostList.map(item => {
            if (!item.costValue) {
              costFlag = false;
            }
          })
          if (!costFlag) {
            this.$message.error('请将目标成本的成本&预算填写完整');
            return;
          }
          this.saveToServer(moduleFormRes);
        } else { /* 草稿 */
          this.saveToServer(moduleFormRes);
        }
      },
      saveToServer(moduleFormRes) {
        if (this.loading) return;
        this.loading = true;
        this.pdsFileModelBaseDto.pdsPlanningModelPicsList = this.pdsFileModelBaseDto.pdsFileModelPbsPicsList;
        const baseParams = JSON.parse(JSON.stringify(this.pdsFileModelBaseDto));
        const detailParams = JSON.parse(JSON.stringify(this.detail));
        baseParams.certsDvs = baseParams.certsDvs.join();
        baseParams.productCategoryIds = baseParams.pdsConfCategory.join();
        baseParams.customerIds = baseParams.customerIds.join();
        detailParams.pdsPlanningManual.manualLanguageDvs = detailParams.pdsPlanningManual.manualLanguageDvs.join();
        /* 市场定位 */
        detailParams.pdsConfMarketList.map(item => {
          item.isChecked = item.isChecked ? 1 : 0;
        })
        /* 包装方式 */
        this.packageTypeList.map(item => {
          detailParams.pdsPlanningPacking[item] = detailParams.pdsPlanningPacking.packageType == item ? 1 : 0;
        })
        /* 销售区域 */
        detailParams.pdsPlanningModelSalesAreasList = [];
        this.detail.pdsPlanningModelSalesAreasList.map(item => {
          detailParams.pdsPlanningModelSalesAreasList.push({salesAreaDv: item});
        })
        /* 产品档案 */
        detailParams.pdsPlanningModelAccessories = moduleFormRes.data.showAccessoriesList;
        detailParams.pdsPlanningModelFeaturesList = moduleFormRes.data.showFeaturesList;
        detailParams.pdsModuleItemsAndValueVOList = moduleFormRes.data.showModules;
        detailParams.pdsModuleItemsAndValueVOList.map(moduleItem => {
          if (moduleItem.paramsList && moduleItem.paramsList.length) {
            moduleItem.paramsList.map(paramsItem => {
              paramsItem.paramValue = moduleItem.formData[paramsItem.id];
              paramsItem.paramMaxValue =
                moduleItem.formData[paramsItem.id + 'm'];
            });
          }
        });

        delete baseParams.pdsConfCategory;
        const postParams = Object.assign(
          baseParams,
          detailParams
        );
        console.log('postParams', postParams);
        planApi.save(postParams).then(res => {
          console.log(res);
          if (res.code === 200) {
            this.$message.success((this.detail.status ? '提交' : '保存草稿') + '成功')
            this.$store.commit('ADD_LIST_REFRESH', this.$route.path.slice(0, this.$route.path.lastIndexOf('/')));
            if (this.detail.status) {
              this.$store.dispatch('delActiveViews');
            }
          } else {
            this.$message.warning((this.detail.status ? '提交' : '保存草稿') + '失败')
          }
          this.loading = false;
        }).catch(err => {
          console.log(err);
          this.loading = false;
        })
      }
    }
  };
</script>
